package top.codedance.iotp.server.net.handle.subhandle.controller.http.async;

import com.alibaba.fastjson.JSONObject;
import top.codedance.iotp.common.constent.Command;
import top.codedance.iotp.server.net.WsServer;
import top.codedance.iotp.server.net.handle.WsChannelHandler;
import top.codedance.iotp.server.net.handle.exception.NotAccessException;
import top.codedance.iotp.server.net.handle.subhandle.controller.AdapterWsController;

import java.util.HashSet;

public class ClientsStatusHandler extends AdapterWsController {

    @Override
    public void doSubHandler(WsChannelHandler wsChannelHandle, String clientId, JSONObject jsonObject) {
        try {
            if (!adminVerification()) {
                throw new NotAccessException();
            }
            if(!WsServer.localTaskClients.containsKey(Command.ASYNC_CSTATUS_COMMAND_RECEIVE)){
                WsServer.localTaskClients.put(Command.ASYNC_CSTATUS_COMMAND_RECEIVE, new HashSet<>());
            }
            WsServer.localTaskClients.get(Command.ASYNC_CSTATUS_COMMAND_RECEIVE).add(clientId);
        } catch (NotAccessException e){
            wsChannelHandle.wsSend(clientId, response403( "No access"));
        }
    }
}
